<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="日期" prop="dataDate">
        <el-date-picker
          clearable
          v-model="queryParams.dataDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          :icon="!isOpen ? 'el-icon-arrow-down' : 'el-icon-arrow-up'"
          size="mini"
          @click="shouqi"
          >展开/收起</el-button
        >
      </el-form-item>

      <div v-if="isOpen">
        <el-form-item label="店铺id" prop="shopId">
          <el-input
            v-model="queryParams.shopId"
            placeholder="请输入店铺id"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <!-- <el-form-item label="日期" prop="dataDate">
        <el-date-picker
          clearable
          v-model="queryParams.dataDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择日期"
        >
        </el-date-picker>
      </el-form-item> -->
        <el-form-item label="店铺名称" prop="shopName">
          <el-input
            v-model="queryParams.shopName"
            placeholder="请输入店铺名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="销售目标" prop="salesTarget">
          <el-input
            v-model="queryParams.salesTarget"
            placeholder="请输入销售目标"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="销售额" prop="saleAmount">
          <el-input
            v-model="queryParams.saleAmount"
            placeholder="请输入销售额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="退款金额" prop="returnAmount">
          <el-input
            v-model="queryParams.returnAmount"
            placeholder="请输入退款金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="净销售额" prop="netSalesAmount">
          <el-input
            v-model="queryParams.netSalesAmount"
            placeholder="请输入净销售额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="下单数" prop="ordersNumber">
          <el-input
            v-model="queryParams.ordersNumber"
            placeholder="请输入下单数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="客单价" prop="customerUnitPrice">
          <el-input
            v-model="queryParams.customerUnitPrice"
            placeholder="请输入客单价"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="商品销售成本" prop="saleCostPro">
          <el-input
            v-model="queryParams.saleCostPro"
            placeholder="请输入商品销售成本"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="退款率" prop="refundRate">
          <el-input
            v-model="queryParams.refundRate"
            placeholder="请输入退款率"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="访客数" prop="visitorCount">
          <el-input
            v-model="queryParams.visitorCount"
            placeholder="请输入访客数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="支付买家数(成交人数)" prop="paidCustomers">
          <el-input
            v-model="queryParams.paidCustomers"
            placeholder="请输入支付买家数(成交人数)"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="收藏加购人数" prop="favoriteCartCount">
          <el-input
            v-model="queryParams.favoriteCartCount"
            placeholder="请输入收藏加购人数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="加购人数" prop="cartCount">
          <el-input
            v-model="queryParams.cartCount"
            placeholder="请输入加购人数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="收藏加购率" prop="favoriteCartRate">
          <el-input
            v-model="queryParams.favoriteCartRate"
            placeholder="请输入收藏加购率"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="加购率" prop="cartRate">
          <el-input
            v-model="queryParams.cartRate"
            placeholder="请输入加购率"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="支付转化率" prop="paymentConversionRate">
          <el-input
            v-model="queryParams.paymentConversionRate"
            placeholder="请输入支付转化率"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="赠品数" prop="giftCount">
          <el-input
            v-model="queryParams.giftCount"
            placeholder="请输入赠品数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="赠品率" prop="giftRate">
          <el-input
            v-model="queryParams.giftRate"
            placeholder="请输入赠品率"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="ROI" prop="roi">
          <el-input
            v-model="queryParams.roi"
            placeholder="请输入ROI"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="获客成本" prop="customerAcquisitionCost">
          <el-input
            v-model="queryParams.customerAcquisitionCost"
            placeholder="请输入获客成本"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="老客数" prop="oldCustomerCount">
          <el-input
            v-model="queryParams.oldCustomerCount"
            placeholder="请输入老客数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="新客数" prop="newCustomerCount">
          <el-input
            v-model="queryParams.newCustomerCount"
            placeholder="请输入新客数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="新客占比" prop="newCustomerRatio">
          <el-input
            v-model="queryParams.newCustomerRatio"
            placeholder="请输入新客占比"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="老客占比" prop="oldCustomerRatio">
          <el-input
            v-model="queryParams.oldCustomerRatio"
            placeholder="请输入老客占比"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="UV价值" prop="uvValue">
          <el-input
            v-model="queryParams.uvValue"
            placeholder="请输入UV价值"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="营销花费" prop="marketingCost">
          <el-input
            v-model="queryParams.marketingCost"
            placeholder="请输入营销花费"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="营销销售额" prop="marketingSalesAmount">
          <el-input
            v-model="queryParams.marketingSalesAmount"
            placeholder="请输入营销销售额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="营销付费点击数" prop="marketingClick">
          <el-input
            v-model="queryParams.marketingClick"
            placeholder="请输入营销付费点击数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="营销加购数" prop="marketingCartCount">
          <el-input
            v-model="queryParams.marketingCartCount"
            placeholder="请输入营销加购数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="营销收藏数" prop="marketingFavoriteCount">
          <el-input
            v-model="queryParams.marketingFavoriteCount"
            placeholder="请输入营销收藏数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="营销支付人数" prop="marketingPaidBuyerCount">
          <el-input
            v-model="queryParams.marketingPaidBuyerCount"
            placeholder="请输入营销支付人数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="营销收藏加购率" prop="marketingFavoriteRate">
          <el-input
            v-model="queryParams.marketingFavoriteRate"
            placeholder="请输入营销收藏加购率"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="营销加购率" prop="marketingCartRate">
          <el-input
            v-model="queryParams.marketingCartRate"
            placeholder="请输入营销加购率"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item
          label="营销支付转化率"
          prop="marketingPaymentConversionRate"
        >
          <el-input
            v-model="queryParams.marketingPaymentConversionRate"
            placeholder="请输入营销支付转化率"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="年" prop="dataYear">
          <el-input
            v-model="queryParams.dataYear"
            placeholder="请输入年"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="季" prop="dataQuarter">
          <el-input
            v-model="queryParams.dataQuarter"
            placeholder="请输入季"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="月" prop="dataMonth">
          <el-input
            v-model="queryParams.dataMonth"
            placeholder="请输入月"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="周" prop="dataWeek">
          <el-input
            v-model="queryParams.dataWeek"
            placeholder="请输入周"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </div>
      <!-- <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item> -->
    </el-form>

    <el-row>
      <el-col :span="9">
        <timeSearch
          @getDateArr="getDateArr"
          @changDay="changDay"
          :timeArr="timeArr"
          :dayActive="this.dayActive"
          :dayLimit="1095"
        />
      </el-col>
    </el-row>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['sale:BiTbSaleDwd:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['sale:BiTbSaleDwd:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['sale:BiTbSaleDwd:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['sale:BiTbSaleDwd:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleRefresh"
          >同步数据</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="BiTbSaleDwdList"
      @selection-change="handleSelectionChange"
      :height="650"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="店铺id" align="center" prop="shopId" />
      <el-table-column label="日期" align="center" prop="dataDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dataDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="店铺名称" align="center" prop="shopName" />
      <el-table-column label="销售目标" align="center" prop="salesTarget" />
      <el-table-column label="销售额" align="center" prop="saleAmount" />
      <el-table-column label="退款金额" align="center" prop="returnAmount" />
      <el-table-column label="净销售额" align="center" prop="netSalesAmount" />
      <el-table-column label="下单数" align="center" prop="ordersNumber" />
      <el-table-column label="客单价" align="center" prop="customerUnitPrice" />
      <el-table-column label="商品销售成本" align="center" prop="saleCostPro" />
      <el-table-column label="退款率" align="center" prop="refundRate" />
      <el-table-column label="访客数" align="center" prop="visitorCount" />
      <el-table-column
        width="180"
        label="支付买家数(成交人数)"
        align="center"
        prop="paidCustomers"
      />
      <el-table-column
        label="收藏加购人数"
        align="center"
        prop="favoriteCartCount"
      />
      <el-table-column label="加购人数" align="center" prop="cartCount" />
      <el-table-column
        label="收藏加购率"
        align="center"
        prop="favoriteCartRate"
      />
      <el-table-column label="加购率" align="center" prop="cartRate" />
      <el-table-column
        label="支付转化率"
        align="center"
        prop="paymentConversionRate"
      />
      <el-table-column label="赠品数" align="center" prop="giftCount" />
      <el-table-column label="赠品率" align="center" prop="giftRate" />
      <el-table-column label="ROI" align="center" prop="roi" />
      <el-table-column
        label="获客成本"
        align="center"
        prop="customerAcquisitionCost"
      />
      <el-table-column label="老客数" align="center" prop="oldCustomerCount" />
      <el-table-column label="新客数" align="center" prop="newCustomerCount" />
      <el-table-column
        label="新客占比"
        align="center"
        prop="newCustomerRatio"
      />
      <el-table-column
        label="老客占比"
        align="center"
        prop="oldCustomerRatio"
      />
      <el-table-column label="UV价值" align="center" prop="uvValue" />
      <el-table-column label="营销花费" align="center" prop="marketingCost" />
      <el-table-column
        label="营销销售额"
        align="center"
        prop="marketingSalesAmount"
      />
      <el-table-column
        label="营销付费点击数"
        align="center"
        prop="marketingClick"
      />
      <el-table-column
        label="营销加购数"
        align="center"
        prop="marketingCartCount"
      />
      <el-table-column
        label="营销收藏数"
        align="center"
        prop="marketingFavoriteCount"
      />
      <el-table-column
        label="营销支付人数"
        align="center"
        prop="marketingPaidBuyerCount"
      />
      <el-table-column
        label="营销收藏加购率"
        align="center"
        prop="marketingFavoriteRate"
      />
      <el-table-column
        label="营销加购率"
        align="center"
        prop="marketingCartRate"
      />
      <el-table-column
        label="营销支付转化率"
        align="center"
        prop="marketingPaymentConversionRate"
      />
      <el-table-column label="年" align="center" prop="dataYear" />
      <el-table-column label="季" align="center" prop="dataQuarter" />
      <el-table-column label="月" align="center" prop="dataMonth" />
      <el-table-column label="周" align="center" prop="dataWeek" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['sale:BiTbSaleDwd:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['sale:BiTbSaleDwd:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改淘系销售营销数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="店铺id" prop="shopId">
          <el-input v-model="form.shopId" placeholder="请输入店铺id" />
        </el-form-item>
        <el-form-item label="日期" prop="dataDate">
          <el-date-picker
            clearable
            v-model="form.dataDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="店铺名称" prop="shopName">
          <el-input v-model="form.shopName" placeholder="请输入店铺名称" />
        </el-form-item>
        <el-form-item label="销售目标" prop="salesTarget">
          <el-input v-model="form.salesTarget" placeholder="请输入销售目标" />
        </el-form-item>
        <el-form-item label="销售额" prop="saleAmount">
          <el-input v-model="form.saleAmount" placeholder="请输入销售额" />
        </el-form-item>
        <el-form-item label="退款金额" prop="returnAmount">
          <el-input v-model="form.returnAmount" placeholder="请输入退款金额" />
        </el-form-item>
        <el-form-item label="净销售额" prop="netSalesAmount">
          <el-input
            v-model="form.netSalesAmount"
            placeholder="请输入净销售额"
          />
        </el-form-item>
        <el-form-item label="下单数" prop="ordersNumber">
          <el-input v-model="form.ordersNumber" placeholder="请输入下单数" />
        </el-form-item>
        <el-form-item label="客单价" prop="customerUnitPrice">
          <el-input
            v-model="form.customerUnitPrice"
            placeholder="请输入客单价"
          />
        </el-form-item>
        <el-form-item label="商品销售成本" prop="saleCostPro">
          <el-input
            v-model="form.saleCostPro"
            placeholder="请输入商品销售成本"
          />
        </el-form-item>
        <el-form-item label="退款率" prop="refundRate">
          <el-input v-model="form.refundRate" placeholder="请输入退款率" />
        </el-form-item>
        <el-form-item label="访客数" prop="visitorCount">
          <el-input v-model="form.visitorCount" placeholder="请输入访客数" />
        </el-form-item>
        <el-form-item label="支付买家数(成交人数)" prop="paidCustomers">
          <el-input
            v-model="form.paidCustomers"
            placeholder="请输入支付买家数(成交人数)"
          />
        </el-form-item>
        <el-form-item label="收藏加购人数" prop="favoriteCartCount">
          <el-input
            v-model="form.favoriteCartCount"
            placeholder="请输入收藏加购人数"
          />
        </el-form-item>
        <el-form-item label="加购人数" prop="cartCount">
          <el-input v-model="form.cartCount" placeholder="请输入加购人数" />
        </el-form-item>
        <el-form-item label="收藏加购率" prop="favoriteCartRate">
          <el-input
            v-model="form.favoriteCartRate"
            placeholder="请输入收藏加购率"
          />
        </el-form-item>
        <el-form-item label="加购率" prop="cartRate">
          <el-input v-model="form.cartRate" placeholder="请输入加购率" />
        </el-form-item>
        <el-form-item label="支付转化率" prop="paymentConversionRate">
          <el-input
            v-model="form.paymentConversionRate"
            placeholder="请输入支付转化率"
          />
        </el-form-item>
        <el-form-item label="赠品数" prop="giftCount">
          <el-input v-model="form.giftCount" placeholder="请输入赠品数" />
        </el-form-item>
        <el-form-item label="赠品率" prop="giftRate">
          <el-input v-model="form.giftRate" placeholder="请输入赠品率" />
        </el-form-item>
        <el-form-item label="ROI" prop="roi">
          <el-input v-model="form.roi" placeholder="请输入ROI" />
        </el-form-item>
        <el-form-item label="获客成本" prop="customerAcquisitionCost">
          <el-input
            v-model="form.customerAcquisitionCost"
            placeholder="请输入获客成本"
          />
        </el-form-item>
        <el-form-item label="老客数" prop="oldCustomerCount">
          <el-input
            v-model="form.oldCustomerCount"
            placeholder="请输入老客数"
          />
        </el-form-item>
        <el-form-item label="新客数" prop="newCustomerCount">
          <el-input
            v-model="form.newCustomerCount"
            placeholder="请输入新客数"
          />
        </el-form-item>
        <el-form-item label="新客占比" prop="newCustomerRatio">
          <el-input
            v-model="form.newCustomerRatio"
            placeholder="请输入新客占比"
          />
        </el-form-item>
        <el-form-item label="老客占比" prop="oldCustomerRatio">
          <el-input
            v-model="form.oldCustomerRatio"
            placeholder="请输入老客占比"
          />
        </el-form-item>
        <el-form-item label="UV价值" prop="uvValue">
          <el-input v-model="form.uvValue" placeholder="请输入UV价值" />
        </el-form-item>
        <el-form-item label="营销花费" prop="marketingCost">
          <el-input v-model="form.marketingCost" placeholder="请输入营销花费" />
        </el-form-item>
        <el-form-item label="营销销售额" prop="marketingSalesAmount">
          <el-input
            v-model="form.marketingSalesAmount"
            placeholder="请输入营销销售额"
          />
        </el-form-item>
        <el-form-item label="营销付费点击数" prop="marketingClick">
          <el-input
            v-model="form.marketingClick"
            placeholder="请输入营销付费点击数"
          />
        </el-form-item>
        <el-form-item label="营销加购数" prop="marketingCartCount">
          <el-input
            v-model="form.marketingCartCount"
            placeholder="请输入营销加购数"
          />
        </el-form-item>
        <el-form-item label="营销收藏数" prop="marketingFavoriteCount">
          <el-input
            v-model="form.marketingFavoriteCount"
            placeholder="请输入营销收藏数"
          />
        </el-form-item>
        <el-form-item label="营销支付人数" prop="marketingPaidBuyerCount">
          <el-input
            v-model="form.marketingPaidBuyerCount"
            placeholder="请输入营销支付人数"
          />
        </el-form-item>
        <el-form-item label="营销收藏加购率" prop="marketingFavoriteRate">
          <el-input
            v-model="form.marketingFavoriteRate"
            placeholder="请输入营销收藏加购率"
          />
        </el-form-item>
        <el-form-item label="营销加购率" prop="marketingCartRate">
          <el-input
            v-model="form.marketingCartRate"
            placeholder="请输入营销加购率"
          />
        </el-form-item>
        <el-form-item
          label="营销支付转化率"
          prop="marketingPaymentConversionRate"
        >
          <el-input
            v-model="form.marketingPaymentConversionRate"
            placeholder="请输入营销支付转化率"
          />
        </el-form-item>
        <el-form-item label="年" prop="dataYear">
          <el-input v-model="form.dataYear" placeholder="请输入年" />
        </el-form-item>
        <el-form-item label="季" prop="dataQuarter">
          <el-input v-model="form.dataQuarter" placeholder="请输入季" />
        </el-form-item>
        <el-form-item label="月" prop="dataMonth">
          <el-input v-model="form.dataMonth" placeholder="请输入月" />
        </el-form-item>
        <el-form-item label="周" prop="dataWeek">
          <el-input v-model="form.dataWeek" placeholder="请输入周" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listBiTbSaleDwd,
  getBiTbSaleDwd,
  delBiTbSaleDwd,
  addBiTbSaleDwd,
  updateBiTbSaleDwd,
  synData,
} from "@/api/sale/BiTbSaleDwd";
import timeSearch from "@/common/day";
export default {
  name: "BiTbSaleDwd",
  components: { timeSearch },
  data() {
    return {
      dayActive: 2,
      timeArr: [
        { value: "2", label: "昨天" },
        { value: "7", label: "最近7天" },
        { value: "30", label: "最近30天" },
        { value: "365", label: "最近一年" },
        { value: "1", label: "日" },
      ],
      timeGap: { startTime: "", endTime: "" },
      isOpen: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 淘系销售营销数据表格数据
      BiTbSaleDwdList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        shopId: null,
        dataDate: null,
        shopName: null,
        salesTarget: null,
        saleAmount: null,
        returnAmount: null,
        netSalesAmount: null,
        ordersNumber: null,
        customerUnitPrice: null,
        saleCostPro: null,
        refundRate: null,
        visitorCount: null,
        paidCustomers: null,
        favoriteCartCount: null,
        cartCount: null,
        favoriteCartRate: null,
        cartRate: null,
        paymentConversionRate: null,
        giftCount: null,
        giftRate: null,
        roi: null,
        customerAcquisitionCost: null,
        oldCustomerCount: null,
        newCustomerCount: null,
        newCustomerRatio: null,
        oldCustomerRatio: null,
        uvValue: null,
        marketingCost: null,
        marketingSalesAmount: null,
        marketingClick: null,
        marketingCartCount: null,
        marketingFavoriteCount: null,
        marketingPaidBuyerCount: null,
        marketingFavoriteRate: null,
        marketingCartRate: null,
        marketingPaymentConversionRate: null,
        dataYear: null,
        dataQuarter: null,
        dataMonth: null,
        dataWeek: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        shopId: [
          { required: true, message: "店铺id不能为空", trigger: "blur" },
        ],
        dataDate: [
          { required: true, message: "日期不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 打开加载层
    openLoading() {
      this.$modal.loading("正在加载数据，请稍候！");
    },
    /** 刷新缓存按钮操作 Warning*/
    handleRefresh() {
      // this.$modal.msgWarning("数据正在同步，请稍候");

      const obj = {
        startTime: this.timeGap.startTime,
        endTime: this.timeGap.endTime,
      };
      this.openLoading();
      synData(obj).then(() => {
        this.$modal.closeLoading();
        this.$modal.msgSuccess("同步数据成功");
        this.getList();
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    //时间控件
    changDay(val) {
      this.dayActive = val;
      this.timeGap.startTime = val[0];
      this.timeGap.endTime = val[1];
    },
    getDateArr(value) {
      this.timeGap.startTime = value[0];
      this.timeGap.endTime = value[1];
      console.log(JSON.stringify(this.timeGap));
      this.dayActive = 1;
    },
    //搜索栏展示与收起
    shouqi() {
      // console.log(1);
      this.isOpen = !this.isOpen;
    },
    /** 查询淘系销售营销数据列表 */
    getList() {
      this.loading = true;
      listBiTbSaleDwd(this.queryParams).then((response) => {
        this.BiTbSaleDwdList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        shopId: null,
        dataDate: null,
        shopName: null,
        salesTarget: null,
        saleAmount: null,
        returnAmount: null,
        netSalesAmount: null,
        ordersNumber: null,
        customerUnitPrice: null,
        saleCostPro: null,
        refundRate: null,
        visitorCount: null,
        paidCustomers: null,
        favoriteCartCount: null,
        cartCount: null,
        favoriteCartRate: null,
        cartRate: null,
        paymentConversionRate: null,
        giftCount: null,
        giftRate: null,
        roi: null,
        customerAcquisitionCost: null,
        oldCustomerCount: null,
        newCustomerCount: null,
        newCustomerRatio: null,
        oldCustomerRatio: null,
        uvValue: null,
        marketingCost: null,
        marketingSalesAmount: null,
        marketingClick: null,
        marketingCartCount: null,
        marketingFavoriteCount: null,
        marketingPaidBuyerCount: null,
        marketingFavoriteRate: null,
        marketingCartRate: null,
        marketingPaymentConversionRate: null,
        dataYear: null,
        dataQuarter: null,
        dataMonth: null,
        dataWeek: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加淘系销售营销数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBiTbSaleDwd(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改淘系销售营销数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBiTbSaleDwd(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBiTbSaleDwd(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除淘系销售营销数据编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBiTbSaleDwd(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "sale/BiTbSaleDwd/export",
        {
          ...this.queryParams,
        },
        `BiTbSaleDwd_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
